/**
 *
 * This Class contains alle basic techniques/methods for the AI.
 * Tt's also the core for the valuation regulation for the alpha-beta pruning
 */
package AIEngine;

public class BasicAI {

    /**
     * Transforms a boolean value to a integer value
     *
     * @param black paylerflag
     * @return -1 if black is true and 1 if black is false
     */
    public static int colorToInt(boolean black) {
        if (black) {
            return -1;
        } else {
            return 1;
        }
    }

    /**
     * This method allows to generate a new board deppending on the current board
     * and adding a additional marbel to an empty place
     * 
     * @param field the current board
     * @param coord the coordinates wehre the marbel is supposed to be set
     * @param campe playferfalg
     * @return field new Board with the move that was to set
     */
    public static int[][] setOnBoard(int[][] field, int[] coord, boolean campe) {
        int i, j;
        i = coord[0];
        j = coord[1];
        if (Math.abs(field[i][j]) != 1) {
            if (campe) {
                field[i][j] = -1;
            } else {
                field[i][j] = 1;
            }
        }

        return field;
    }

    /**
     * Shows if a cell in a array is empty
     * @param cell <=> array[x][y]
     * @return true if the cell is empty otherwise false
     */
    public static boolean isEmpty(int cell) {
        if (Math.abs(cell) != 1) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Shows if a cell in a array is flaged with a preferencevalue
     *
     * @param cell  <=> array[x][y]
     * @return true if ther is a value, false if the cell is empty
     */
    public static boolean haveAPreference(int cell) {
        if (Math.abs(cell) != 1 && cell != 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Runs through the howl array and saves the highest value to maxeValue (according to amount)
     *
     * @param field
     * @param black
     * @return maxValue, highest value in the array
     */
    public static int getMaxValue(int[][] field, boolean black) {
        int maxValue = 0;
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 6; j++) {
                if (maxValue < Math.abs(field[i][j]) && (Math.abs(field[i][j]) != 1)) {
                    maxValue = Math.abs(field[i][j]);
                }
            }

        }
        if (black) {
            return maxValue * -1;
        } else {
            return maxValue;
        }
    }

    /**
     * Counts how many times the MaxValue appears in the array
     *
     * see getMaxValue
     * @param field is the target that is supposed to be scaned.
     * @param black represents the player
     * @return count is the result of the search
     */
    public static int countMaxValue(int[][] field, boolean black) {
        int count = 0;
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 6; j++) {
                if (Math.abs(field[i][j]) == getMaxValue(field, black)) {
                    count += 1;
                }
            }
        }
        return count;
    }

    /**
     * This method is supposed to return the coordinates of a MaxValue in a array
     *
     * see isEmpty
     * see getMaxValue
     * @param field
     * @param black
     * @return if everything works fine the return value will be a array
     * int[]{i, j} (row,column) otherwise
     * ther will be returned {-1337, -1337} as an errorflag
     */
    public static int[] getMaxValueCoord(int[][] field, boolean black) {
        int maxValue = getMaxValue(field, black);

        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 6; j++) {

                if (Math.abs(field[i][j]) == Math.abs(maxValue) && isEmpty(field[i][j])) {
                    return new int[]{i, j};
                }
            }

        }
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 6; j++) {
                if (isEmpty(field[i][j])) {
                    return new int[]{i, j};
                }

            }
        }

        return new int[]{-1337, -1337};
    }

    /**
     * Sums up all preference values from a array
     *
     * @param field is the targetarray
     * @param black is the playerflag
     * @return sum a integer value
     */
    static int getfullValue(int[][] field, boolean black) {
        int sum = 0;
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 6; j++) {
                if (Math.abs(field[i][j]) != 1) {
                    sum += field[i][j];
                }
            }
        }
        if (black) {
            return sum * -1;
        } else {
            return sum;
        }
    }

    /**
     * Scans the target array and sets a preference value to the next empty cell.
     * As the name suggests only a sequence of two equal marbles will be recognized
     * by this method.
     * The ambition of this method is to avoid three equal marbles in a row of the same
     * quadrant
     * The preference values will be set on the array
     *
     * @param field target array
     * @param black player flag
     */
    public static void searchTwoInARow(int[][] field, boolean black) {
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 5; j++) {
                if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 1])) {



                    if (j < 3 && j - 1 > -1 && isEmpty(field[i][j - 1])) {
                        if (haveAPreference(field[i][j - 1])) {
                            field[i][j - 1] = Math.abs(3 * field[i][j] * field[i][j - 1]) * colorToInt(black);
                        } else {
                            field[i][j - 1] += 3 * field[i][j];
                        }

                    } else {
                        if (j + 2 < 6 && isEmpty(field[i][j + 2])) {
                            if (haveAPreference(field[i][j + 2])) {
                                field[i][j + 2] = Math.abs(3 * field[i][j] * field[i][j + 2]) * colorToInt(black);
                            } else {
                                field[i][j + 2] += 3 * field[i][j];
                            }

                        }
                        if ((j - 1 > -1) && isEmpty(field[i][j - 1])) {
                            if (haveAPreference(field[i][j - 1])) {
                                field[i][j - 1] = Math.abs(3 * field[i][j] * field[i][j - 1]) * colorToInt(black);
                            } else {
                                field[i][j - 1] += 3 * field[i][j];
                            }

                        }
                    }

                }
            }
        }
    }

    /**
     * Scans the targetarray and sets a preference value to the next empty cell.
     * Only a sequence of three equal marbles will be recognized
     * by this method.
     * The ambition of this method is to avoid four equal marbles in a row over two neighbor
     * quadrants
     * The preference values will be set on the array
     *
     * @param field target array
     * @param black player flag
     */
    public static void searchPossibleFourInARow(int[][] field, boolean black) {
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 4; j++) {
                if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 1]) && (field[i][j + 1] == field[i][j + 2])) {



                    if (j < 3 && j - 1 > -1 && isEmpty(field[i][j - 1])) {
                        if (haveAPreference(field[i][j - 1])) {
                            field[i][j - 1] = Math.abs(3 * field[i][j] * field[i][j - 1]) * colorToInt(black);
                        } else {
                            field[i][j - 1] += 3 * field[i][j];
                        }

                    } else {
                        if (j + 3 < 6 && isEmpty(field[i][j + 3])) {
                            if (haveAPreference(field[i][j + 3])) {
                                field[i][j + 3] = Math.abs(3 * field[i][j] * field[i][j + 3]) * colorToInt(black);
                            } else {
                                field[i][j + 3] += 3 * field[i][j];
                            }

                        }
                        if ((j - 1 > -1) && isEmpty(field[i][j - 1])) {
                            if (haveAPreference(field[i][j - 1])) {
                                field[i][j - 1] = Math.abs(3 * field[i][j] * field[i][j - 1]) * colorToInt(black);
                            } else {
                                field[i][j - 1] += 3 * field[i][j];
                            }

                        }
                    }

                }
            }
        }
    }

    /**
     * Scans the targetarray and sets a preference value to the next empty cell.
     * Only a sequence of two equal marbles,over three cells will be recognized
     * by this method.
     * The ambition of this method is to avoid three equal marbles in a row of the same
     * quadrant(e.g[x][][x] will be avoid)
     * The preference values will be set on the array
     *
     * @param field target array
     * @param black player flag
     */
    public static void searchTwoOverThreeInARow(int[][] field, boolean black) {
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 5; j++) {
                if ((j + 2 <= 5)) {
                    if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 2])) {
                        if (isEmpty(field[i][j + 1])) {
                            if (haveAPreference(field[i][j + 1])) {
                                field[i][j + 1] = Math.abs(3 * field[i][j] * field[i][j + 1]) * colorToInt(black);
                            } else {
                                field[i][j + 1] += 3 * field[i][j];
                            }

                        }
                    }
                }
            }
        }

    }

    /**
     * Scans the targetarray and sets a preference value to the next empty cell.
     * Only a sequence of two equal marbles in a column will be recognized
     * by this method.
     * The ambition of this method is to avoid three equal marbles in a column of the same
     * quadrant
     * The preference values will be set on the array
     *
     * @param field target array
     * @param black player flag
     */
    public static void searchTwoInAColumn(int[][] field, boolean black) {
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 6; j++) {
                if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 1][j])) {

                    if (i + 2 <= 5) {

                        if ((i - 1 > -1 && i < 3) && isEmpty(field[i - 1][j])) {
                            if (haveAPreference(field[i - 1][j])) {
                                field[i - 1][j] = Math.abs(3 * field[i][j] * field[i - 1][j]) * colorToInt(black);
                            } else {
                                field[i - 1][j] += 3 * field[i][j];
                            }


                        } else {

                            if (isEmpty(field[i + 2][j]) && (i + 2 < 6)) {
                                if (haveAPreference(field[i + 2][j])) {
                                    field[i + 2][j] = Math.abs(3 * field[i][j] * field[i + 2][j]) * colorToInt(black);
                                } else {
                                    field[i + 2][j] += 3 * field[i][j];
                                }

                            }
                        }

                    } else {
                        if (isEmpty(field[i - 1][j]) && (i - 1 > -1)) {
                            if (haveAPreference(field[i - 1][j])) {
                                field[i - 1][j] = Math.abs(3 * field[i][j] * field[i - 1][j]) * colorToInt(black);
                            } else {
                                field[i - 1][j] += 3 * field[i][j];
                            }

                        }
                    }
                }
            }
        }
    }

    /**
     * Scans the targetarray and sets a preference value to the next empty cell.
     * Only a sequence of three equal marbles in a column will be recognized
     * by this method.
     * The ambition of this method is to avoid four equal marbles in a column over two neighbour
     * quadrants
     * The preference values will be set on the array
     *
     * @param field target array
     * @param black player flag
     */
    public static void searchPossibleFourInAColumn(int[][] field, boolean black) {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 6; j++) {
                if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 1][j]) && (field[i + 1][j] == field[i + 2][j])) {

                    if (i + 2 <= 5) {

                        if ((i - 1 > -1 && i < 3) && isEmpty(field[i - 1][j])) {
                            if (haveAPreference(field[i - 1][j])) {
                                field[i - 1][j] = Math.abs(3 * field[i][j] * field[i - 1][j]) * colorToInt(black);
                            } else {
                                field[i - 1][j] += 3 * field[i][j];
                            }


                        } else {

                            if ((i + 3 < 6) && isEmpty(field[i + 3][j])) {
                                if (haveAPreference(field[i + 2][j])) {
                                    field[i + 3][j] = Math.abs(3 * field[i][j] * field[i + 2][j]) * colorToInt(black);
                                } else {
                                    field[i + 3][j] += 3 * field[i][j];
                                }

                            }
                        }

                    } else {
                        if ((i - 1 > -1) && isEmpty(field[i - 1][j])) {
                            if (haveAPreference(field[i - 1][j])) {
                                field[i - 1][j] = Math.abs(3 * field[i][j] * field[i - 1][j]) * colorToInt(black);
                            } else {
                                field[i - 1][j] += 3 * field[i][j];
                            }

                        }
                    }
                }
            }
        }
    }

    /**
     * Scans the targetarray and sets a preference value to the next empty cell.
     * Only a sequence of two equal marbles,over three cells will be recognized
     * by this method.
     * The ambition of this method is to avoid three equal marbles in a column of the same
     * quadrant(e.g<br>
     *             [x]<br>
     *             [ ]<br>
     *             [x]<br>
     *             will be avoid)
     * The preference values will be set on the array
     *
     * @param field target array
     * @param black player flag
     */
    public static void searchTwoOverThreeInAColumn(int[][] field, boolean black) {
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 6; j++) {
                if (i + 2 <= 5) {
                    if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 2][j])) {
                        if (isEmpty(field[i + 1][j])) {
                            if (haveAPreference(field[i + 1][j])) {
                                field[i + 1][j] = Math.abs(3 * field[i][j] * field[i + 1][j]) * colorToInt(black);
                            } else {
                                field[i + 1][j] += 3 * field[i][j];
                            }

                        }
                    }
                }
            }

        }
    }

    /**
     * Only a sequence of two equal marbles in the topleft diagnal of the array
     * will be recognised by this method.
     * It only checks the diagonal form the upper left corner to the under right corner,
     * the diangonal upper the main diagonal und the diagonal under the main one.
     * The three diagnals (marked as x) will be checked
     *
     * [x][x][o] [o][o][o] [o][o][o]<br>
     * [x][x][x] [o][o][o] [o][o][o]<br>
     * [o][x][x] [x][o][o] [o][o][o]<br><br>
     *
     * [o][o][o] [x][x][o] [o][o][o]<br>
     * [o][o][o] [x][x][x] [o][o][o]<br>
     * [o][o][o] [o][x][x] [o][o][o]<br><br>
     *
     * [o][o][o] [o][o][o] [x][x][o]<br>
     * [o][o][o] [o][o][o] [x][x][x]<br>
     * [o][o][o] [o][o][o] [o][x][x]<br><br>
     *
     * @param field target array
     * @param black player flag
     */
    public static void searchTwoInADiagonal_TopLeft(int[][] field, boolean black) {
        for (int i = 0; i < 5; i++) {
            if ((Math.abs(field[i][i]) == 1) && (field[i][i] == field[i + 1][i + 1]) && (isEmpty(field[4][4]) || ((Math.abs(field[4][4]) == 1) && field[i][i] == field[4][4]))) {

                if (isEmpty(field[4][4])) {
                    if (haveAPreference(field[4][4])) {
                        field[4][4] = Math.abs(3 * field[i][i] * field[4][4]) * colorToInt(black);
                    } else {
                        field[4][4] += 3 * field[i][i];
                    }
                } else if (i + 2 < 6) {
                    if (isEmpty(field[i + 2][i + 2])) {
                        if (haveAPreference(field[i + 2][i + 2])) {
                            field[i + 2][i + 2] = Math.abs(3 * field[i][i] * field[i + 2][i + 2]) * colorToInt(black);
                        } else {
                            field[i + 2][i + 2] += 3 * field[i][i];
                        }

                    }
                } else if (i - 1 > -1 && (isEmpty(field[1][1]) || (Math.abs(field[1][1]) == 1 && field[i][i] == field[1][1]))) {
                    if (isEmpty(field[1][1])) {
                        if (haveAPreference(field[1][1])) {
                            field[1][1] = Math.abs(3 * field[i][i] * field[1][1]) * colorToInt(black);
                        } else {
                            field[1][1] += 3 * field[i][i];
                        }
                    } else if (isEmpty(field[i - 1][i - 1])) {
                        if (haveAPreference(field[i - 1][i - 1])) {
                            field[i - 1][i - 1] = Math.abs(3 * field[i][i] * field[i - 1][i - 1]) * colorToInt(black);
                        } else {
                            field[i - 1][i - 1] += 3 * field[i][i];
                        }

                    }
                }

            }

            if (i > 0) {
                if ((Math.abs(field[i][i - 1]) == 1) && (field[i][i - 1] == field[i + 1][i])) {

                    if ((i + 2 < 6) && isEmpty(field[i + 2][i + 1])) {
                        if (haveAPreference(field[i + 2][i + 1])) {
                            field[i + 2][i + 1] = Math.abs(3 * field[i][i - 1] * field[i + 2][i + 1]) * colorToInt(black);
                        } else {
                            field[i + 2][i + 1] += 3 * field[i][i - 1];
                        }


                    } else if ((i - 2 > -1) && (isEmpty(field[i - 1][i - 2]))) {
                        if (haveAPreference(field[i - 1][i - 2])) {
                            field[i - 1][i - 2] = Math.abs(3 * field[i][i - 1] * field[i - 1][i - 2]) * colorToInt(black);
                        } else {
                            field[i - 1][i - 2] += 3 * field[i][i - 1];
                        }


                    } else if ((i - 2 > -1) && (isEmpty(field[i - 1][i - 2]))) {
                        if (haveAPreference(field[i - 1][i - 2])) {
                            field[i - 1][i - 2] = Math.abs(3 * field[i][i - 1] * field[i - 1][i - 2]) * colorToInt(black);
                        } else {
                            field[i - 1][i - 2] += 3 * field[i][i - 1];
                        }


                    }
                }

                if (i > 0) {
                    if ((Math.abs(field[i - 1][i]) == 1) && (field[i - 1][i] == field[i][i + 1])) {

                        if ((i + 2 < 6) && isEmpty(field[i + 1][i + 2])) {
                            if (haveAPreference(field[i + 1][i + 2])) {
                                field[i + 1][i + 2] = Math.abs(3 * field[i - 1][i] * field[i + 1][i + 2]) * colorToInt(black);
                            } else {
                                field[i + 1][i + 2] += 3 * field[i - 1][i];
                            }


                        } else if ((i - 2 > -1) && (isEmpty(field[i - 2][i - 1]))) {
                            if (haveAPreference(field[i - 2][i - 1])) {
                                field[i - 2][i - 1] = Math.abs(3 * field[i - 1][i] * field[i - 2][i - 1]) * colorToInt(black);
                            } else {
                                field[i - 2][i - 1] += 3 * field[i - 1][i];
                            }

                        }
                    }
                }
            }
        }
    }

    /**
     * Only a sequence of two equal marbles in the topleft diagnal of the array
     * will be recognised by this method.
     * It only checks the diagonal form the under left corner to the upper right corner,
     * the diangonal upper the main diagonal und the diagonal under the main one.
     * The three diagnals (marked as x) will be checked
     *
     * [o][o][o] [o][o][o] [o][x][x]<br>
     * [o][o][o] [o][o][o] [x][x][x]<br>
     * [o][o][o] [o][o][o] [x][x][o]<br><br>
     *
     * [o][o][o] [o][x][x] [o][o][o]<br>
     * [o][o][o] [x][x][x] [o][o][o]<br>
     * [o][o][o] [x][x][o] [o][o][o]<br><br>
     *
     * [o][x][x] [o][o][o] [o][o][o]<br>
     * [x][x][x] [o][o][o] [o][o][o]<br>
     * [x][x][o] [o][o][o] [o][o][o]<br><br>
     *
     * @param field target array
     * @param black player flag
     */
    public static void searchTwoInADiagonal_BelowLeft(int[][] field, boolean black) {
        for (int i = 5, j = 0; i > 0 && j < 6; i--, j++) {

            if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i - 1][j + 1]) && (((isEmpty(field[1][4])) || ((Math.abs(field[1][4]) == 1) && field[i][j] == field[1][4])))) {

                if (isEmpty(field[1][4])) {
                    if (haveAPreference(field[1][4])) {
                        field[1][4] = Math.abs(3 * field[i][j] * field[1][4]) * colorToInt(black);
                    } else {
                        field[1][4] += 3 * field[i][j];
                    }

                } else if (i - 2 > -1 && j + 2 < 6 && ((isEmpty(field[4][1]) || (Math.abs(field[4][1]) == 1 && field[i][j] == field[4][1])))) {
                    if (isEmpty(field[4][1])) {
                        if (haveAPreference(field[4][1])) {
                            field[4][1] = Math.abs(3 * field[i][j] * field[4][1]) * colorToInt(black);
                        } else {
                            field[4][1] += 3 * field[i][j];
                        }
                    } else if (isEmpty(field[i - 2][j + 2])) {
                        if (haveAPreference(field[i - 2][j + 2])) {
                            field[i - 2][j + 2] = Math.abs(3 * field[i][j] * field[i - 2][j + 2]) * colorToInt(black);
                        } else {
                            field[i - 2][j + 2] += 3 * field[i][j];
                        }
                    }



                } else if (i + 1 < 6 && j - 1 > -1 && isEmpty(field[i + 1][j - 1])) {
                    if (haveAPreference(field[i + 1][j - 1])) {
                        field[i + 1][j - 1] = Math.abs(3 * field[i][j] * field[i + 1][j - 1]) * colorToInt(black);
                    } else {
                        field[i + 1][j - 1] += 3 * field[i][j];
                    }


                }
            }
            if (i - 2 < 5 && j < 5) {
                if (i - 2 > -1 && (Math.abs(field[i - 1][j]) == 1) && (field[i - 1][j] == field[i - 2][j + 1])) {
                    if (i - 3 > -1 && j + 2 < 6 && isEmpty(field[i - 3][j + 2])) {
                        if (haveAPreference(field[i - 3][j + 2])) {
                            field[i - 3][j + 2] = Math.abs(3 * field[i - 1][j] * field[i - 3][j + 2]) * colorToInt(black);
                        } else {
                            field[i - 3][j + 2] += 3 * field[i - 1][j];
                        }
                    } else if (i < 5 && j - 1 > -1 && isEmpty(field[i][j - 1])) {
                        if (haveAPreference(field[i][j - 1])) {
                            field[i][j - 1] = Math.abs(3 * field[i - 1][j] * field[i][j - 1]) * colorToInt(black);
                        } else {
                            field[i][j - 1] += 3 * field[i - 1][j];
                        }
                    }

                }
            }

            if (i - 1 > -1 && j + 2 < 6) {
                if ((Math.abs(field[i][j + 1]) == 1) && (field[i][j + 1] == field[i - 1][j + 2])) {
                    if (i - 2 > -1 && j + 3 < 6 && isEmpty(field[i - 2][j + 3])) {
                        if (haveAPreference(field[i - 2][j + 3])) {
                            field[i - 2][j + 3] = Math.abs(3 * field[i][j + 1] * field[i - 2][j + 3] * colorToInt(black));
                        } else {
                            field[i - 2][j + 3] += 3 * field[i][j + 1];
                        }
                    } else if (i + 1 < 6 && j - 1 > -1 && isEmpty(field[i + 1][j])) {
                        if (haveAPreference(field[i + 1][j])) {
                            field[i + 1][j] = Math.abs(3 * field[i][j + 1] * field[i + 1][j] * colorToInt(black));
                        } else {
                            field[i + 1][j] += 3 * field[i][j + 1];
                        }
                    }
                }

            }

        }


    }

    /**
     * Scans the targetarray and sets a preference value to the next empty cell.
     * Only a sequence of two equal marbles,over three cells, in a diagonal will be recognized
     * by this method.
     * The ambition of this method is to avoid three equal marbles in a the diagnal after rotating a
     * quadrant<br>(e.g<br>
     *             [o][o][x]<br>
     *             [o][o][o]<br>
     *             [x][o][o]<br><br>
     *
     *             will be avoid)<br>
     * The preference values will be set on the array
     *
     * @param field target array
     * @param black player flag
     */
    public static void searchTwoOverThreeInADiagonal(int[][] field, boolean black) {
        if (((Math.abs(field[0][2]) == 1)) && ((field[0][2] == field[2][0]))) {
            if (isEmpty(field[4][4])) {
                if (haveAPreference(field[4][4])) {
                    field[4][4] = Math.abs(6 * field[0][2] * field[4][4] * colorToInt(black));
                } else {
                    field[4][4] += 6 * field[0][2];
                }
            } else if (isEmpty(field[1][1])) {
                if (haveAPreference(field[1][1])) {
                    field[1][1] = Math.abs(6 * field[0][2] * field[1][1] * colorToInt(black));
                } else {
                    field[1][1] += 6 * field[0][2];
                }
            }
        } else if (((Math.abs(field[0][0]) == 1) && ((field[0][0]) == field[2][2]))) {
            if (isEmpty(field[4][4])) {
                if (haveAPreference(field[4][4])) {
                    field[4][4] = Math.abs(6 * field[0][0] * field[4][4]) * colorToInt(black);
                } else {
                    field[4][4] += 6 * field[0][0];
                }
            } else if (isEmpty(field[1][1])) {
                if (haveAPreference(field[1][1])) {
                    field[1][1] = Math.abs(6 * field[0][0] * field[1][1]) * colorToInt(black);
                } else {
                    field[1][1] += 6 * field[0][0];
                }
            }
        }

        if (((Math.abs(field[3][0]) == 1)) && ((field[3][0] == field[5][2]))) {
            if (isEmpty(field[1][4])) {
                if (haveAPreference(field[1][4])) {
                    field[1][4] = Math.abs(6 * field[3][0] * field[1][4]) * colorToInt(black);
                } else {
                    field[1][4] += 6 * field[3][0];
                }
            } else if (isEmpty(field[4][1])) {
                if (haveAPreference(field[4][1])) {
                    field[4][1] = Math.abs(6 * field[3][0] * field[4][1]) * colorToInt(black);
                } else {
                    field[4][1] += 6 * field[3][0];
                }
            }
        } else if ((Math.abs(field[5][0]) == 1) && (field[5][0]) == field[3][2]) {
            if (isEmpty(field[1][4])) {
                if (haveAPreference(field[1][4])) {
                    field[1][4] = Math.abs(6 * field[5][0] * field[1][4]) * colorToInt(black);
                } else {
                    field[1][4] += 6 * field[5][0];
                }
            } else if (isEmpty(field[4][1])) {
                if (haveAPreference(field[4][1])) {
                    field[4][1] = Math.abs(6 * field[5][0] * field[4][1]) * colorToInt(black);
                } else {
                    field[4][1] += 6 * field[5][0];
                }
            }
        }

        if (((Math.abs(field[5][3]) == 1)) && ((field[5][3] == field[3][5]))) {
            if (isEmpty(field[1][1])) {
                if (haveAPreference(field[1][1])) {
                    field[1][1] = Math.abs(6 * field[5][3] * field[1][1]) * colorToInt(black);
                } else {
                    field[1][1] += 6 * field[5][3];
                }
            } else if (isEmpty(field[4][4])) {
                if (haveAPreference(field[4][4])) {
                    field[4][4] = Math.abs(6 * field[5][3] * field[4][4]) * colorToInt(black);
                } else {
                    field[4][4] += 6 * field[5][3];
                }
            }

        } else if ((Math.abs(field[3][3]) == 1) && (field[3][3] == field[5][5])) {
            if (isEmpty(field[1][1])) {
                if (haveAPreference(field[1][1])) {
                    field[1][1] = Math.abs(6 * field[3][3] * field[1][1]) * colorToInt(black);
                } else {
                    field[1][1] += 6 * field[3][3];
                }
            } else if (isEmpty(field[4][4])) {
                if (haveAPreference(field[4][4])) {
                    field[4][4] = Math.abs(6 * field[3][3] * field[4][4]) * colorToInt(black);
                } else {
                    field[4][4] += 6 * field[3][3];
                }
            }
        }

        if (((Math.abs(field[0][3]) == 1)) && ((field[0][3] == field[2][5]))) {
            if (isEmpty(field[4][1])) {
                if (haveAPreference(field[4][1])) {
                    field[4][1] = Math.abs(6 * field[0][3] * field[4][1]) * colorToInt(black);
                } else {
                    field[4][1] += 6 * field[0][3];
                }
            } else if (isEmpty(field[1][4])) {
                if (haveAPreference(field[1][4])) {
                    field[1][4] = Math.abs(6 * field[0][3] * field[1][4]) * colorToInt(black);
                } else {
                    field[1][4] += 6 * field[0][3];
                }
            }
        } else if ((Math.abs(field[0][5]) == 1) && (field[0][5] == field[2][3])) {
            if (isEmpty(field[4][1])) {
                if (haveAPreference(field[4][1])) {
                    field[4][1] = Math.abs(6 * field[0][3] * field[4][1]) * colorToInt(black);
                } else {
                    field[4][1] += 6 * field[0][3];
                }
            } else if (isEmpty(field[1][4])) {
                if (haveAPreference(field[1][4])) {
                    field[1][4] = Math.abs(6 * field[0][3] * field[1][4]) * colorToInt(black);
                } else {
                    field[1][4] += 6 * field[0][3];
                }
            }
        }
    }

    /**
     * The ambition of this method is to find all couples of two equal neighbour marbels in a row
     *
     *
     * @param field target field
     * @param i represents the row
     * @return int[] the first element represent the number of +1 couples<br>
     *               the second  element represent the number of -1 couples<br>
     *               the third element represent the number of all other couples
     */
    public static int[] searchCoupleInARow(int[][] field, int i) {
        int countcoupleminus = 0, countcoupleplus = 0, countemptycouple = 0;
        for (int j = 0; j < 5; j++) {
            if (field[i][j] == 1 && field[i][j] == field[i][j + 1]) {
                countcoupleplus++;
                j++;
            }
            if (field[i][j] == -1 && field[i][j] == field[i][j + 1]) {
                countcoupleminus++;
                j++;
            }
            if (isEmpty(field[i][j]) && isEmpty(field[i][j + 1])) {
                countemptycouple++;
                j++;
            }
        }
        return new int[]{countcoupleplus, countcoupleminus, countemptycouple};
    }

    /**
     * The ambition of this method is to find all sequences of three equal neighbour marbels in a row
     *
     *
     * @param field target field
     * @param i represents the row
     * @return int[] the first element represent the number of +1 sequnces<br>
     *               the second  element represent the number of -1 sequnces
     */
    public static int[] searchThreeInARow(int[][] field, int i) {
        int countthreeminus = 0, countthreeplus = 0;
        for (int j = 0; j < 4; j++) {
            if (field[i][j] == 1 && field[i][j] == field[i][j + 1] && field[i][j + 1] == field[i][j + 2]) {
                countthreeplus++;
                j += 2;
            }
            if (field[i][j] == -1 && field[i][j] == field[i][j + 1] && field[i][j + 1] == field[i][j + 2]) {
                countthreeminus++;
                j += 2;
            }
        }
        return new int[]{countthreeplus, countthreeminus};
    }

    /**
     * The ambition of this method is to find all sequence of four equal neighbour marbels in a row
     *
     *
     * @param field target field
     * @param i represents the row
     * @return int[] the first element represent the number of +1 sequnces<br>
     *               the second  element represent the number of -1 sequnces
     */
    public static int[] searchFourInARow(int[][] field, int i) {
        int countfourplus = 0, countfourminus = 0;
        for (int j = 0; j < 3; j++) {
            if (field[i][j] == 1 && field[i][j] == field[i][j + 1] && field[i][j + 1] == field[i][j + 2] && field[i][j + 2] == field[i][j + 3]) {
                countfourplus++;
                j += 3;
            }
            if (field[i][j] == -1 && field[i][j] == field[i][j + 1] && field[i][j + 1] == field[i][j + 2] && field[i][j + 2] == field[i][j + 3]) {
                countfourminus++;
                j += 3;
            }
        }
        return new int[]{countfourplus, countfourminus};
    }

    /**
     * Scans the target array and sets a preference value to the next empty cell.
     * This method finds a possible constellation of two,three or four equal merblas in a row.
     * Depending on the playerfalg it sets a positiv or negativ preference to the cell that would complet
     * the "fiveinarow"
     *
     * The preference values will be set on the array
     *

     * @param field targetarray
     * @param black playerflag
     */
    public static void searchPossibleFiveInARow(int[][] field, boolean black) {
        for (int i = 0; i < 6; i++) {
            if ((searchCoupleInARow(field, i)[0] == 2 && ((searchCoupleInARow(field, i)[1] == 0) && searchCoupleInARow(field, i)[2] < 2)) || (searchThreeInARow(field, i)[0] == 1 && ((searchThreeInARow(field, i)[1] == 0)))) {
                for (int j = 0; j < 4; j++) {
                    if (field[i][j] == 1 && field[i][j] == field[i][j + 2] && isEmpty(field[i][j + 1])) {
                        if (haveAPreference(field[i][j + 1])) {
                            field[i][j + 1] = Math.abs(3000 * field[i][j] * field[i][j + 1]) * colorToInt(black);
                        } else {
                            field[i][j + 1] += 3000 * field[i][j];
                        }
                    }
                }
            }

            if (searchFourInARow(field, i)[0] == 1) {
                for (int j = 0; j < 4; j++) {
                    if (field[i][j] == 1 && field[i][j + 1] == 1 && isEmpty(field[i][j + 2])) {
                        if (haveAPreference(field[i][j + 2])) {
                            field[i][j + 2] = Math.abs(3000 * field[i][j] * field[i][j + 2]) * colorToInt(black);
                        } else {
                            field[i][j + 2] += 3000 * field[i][j];
                        }
                    }
                    if (j - 1 > -1 && field[i][j] == 1 && field[i][j + 1] == 1 && isEmpty(field[i][j - 1])) {
                        if (haveAPreference(field[i][j - 1])) {
                            field[i][j - 1] = Math.abs(3000 * field[i][j] * field[i][j - 1]) * colorToInt(black);
                        } else {
                            field[i][j - 1] += 3000 * field[i][j];
                        }
                    }
                }
            }

            if ((searchCoupleInARow(field, i)[1] == 2 && ((searchCoupleInARow(field, i)[0] == 0) && searchCoupleInARow(field, i)[2] < 2)) || (searchThreeInARow(field, i)[1] == 1 && ((searchThreeInARow(field, i)[0] == 0)))) {
                for (int j = 0; j < 4; j++) {
                    if (field[i][j] == -1 && field[i][j] == field[i][j + 2] && isEmpty(field[i][j + 1])) {
                        if (haveAPreference(field[i][j + 1])) {
                            field[i][j + 1] = Math.abs(3000 * field[i][j] * field[i][j + 1]) * colorToInt(black);
                        } else {
                            field[i][j + 1] += 3000 * field[i][j];
                        }
                    }
                }
            }

            if (searchFourInARow(field, i)[1] == 1) {
                for (int j = 0; j < 4; j++) {
                    if (field[i][j] == -1 && field[i][j + 1] == -1 && isEmpty(field[i][j + 2])) {
                        if (haveAPreference(field[i][j + 2])) {
                            field[i][j + 2] = Math.abs(3000 * field[i][j] * field[i][j + 2]) * colorToInt(black);
                        } else {
                            field[i][j + 2] += 3000 * field[i][j];
                        }
                    }
                    if (j - 1 > -1 && field[i][j] == -1 && field[i][j + 1] == -1 && isEmpty(field[i][j - 1])) {
                        if (haveAPreference(field[i][j - 1])) {
                            field[i][j - 1] = Math.abs(3000 * field[i][j] * field[i][j - 1]) * colorToInt(black);
                        } else {
                            field[i][j - 1] += 3000 * field[i][j];
                        }
                    }
                }
            }
        }
    }

    /**
     * The ambition of this method is to find all couple of two equal neighbour marbels in a column
     *
     *
     * @param field target field
     * @param i represents the row
     * @return int[] the first element represent the number of +1 couples<br>
     *               the second  element represent the number of -1 couples<br>
     *               the third element represent the number of all other couples
     */
    public static int[] searchCoupleInAColumn(int[][] field, int i) {
        int countcoupleminus = 0, countcoupleplus = 0, countemptycouple = 0;
        for (int j = 0; j < 5; j++) {
            if (field[j][i] == 1 && field[j][i] == field[j + 1][i]) {
                countcoupleplus++;
                j++;
            }
            if (field[j][i] == -1 && field[j][i] == field[j + 1][i]) {
                countcoupleminus++;
                j++;
            }
            if (isEmpty(field[j][i]) && isEmpty(field[j + 1][i])) {
                countemptycouple++;
                j++;
            }
        }
        return new int[]{countcoupleplus, countcoupleminus, countemptycouple};
    }

    /**
     * The ambition of this method is to find all sequence of three equal neighbour marbels in a column
     *
     *
     * @param field targetfield
     * @param i represents the row
     * @return int[] the first element represent the number of +1 sequnces<br>
     *               the second  element represent the number of -1 sequnces<br>
     */
    public static int[] searchThreeInAColumn(int[][] field, int i) {
        int countthreeminus = 0, countthreeplus = 0;
        for (int j = 0; j < 4; j++) {
            if (field[j][i] == 1 && field[j][i] == field[j + 1][i] && field[j + 1][i] == field[j + 2][i]) {
                countthreeplus++;
                j += 2;
            }

            if (field[j][i] == -1 && field[j][i] == field[j + 1][i] && field[j + 1][i] == field[j + 2][i]) {
                countthreeminus++;
                j += 2;
            }
        }
        return new int[]{countthreeplus, countthreeminus};
    }

    /**
     * The ambition of this method is to find all sequence of four equal neighbour marbels in a column
     *
     *
     * @param field targetfield
     * @param i represents the row
     * @return int[] the first element represent the number of +1 sequnces
     *               the second  element represent the number of -1 sequnces
     */
    public static int[] searchFourInAColumn(int[][] field, int i) {
        int countfourplus = 0, countfourminus = 0;
        for (int j = 0; j < 3; j++) {
            if (field[j][i] == 1 && field[j][i] == field[j + 1][i] && field[j + 1][i] == field[j + 2][i] && field[j + 2][i] == field[j + 3][i]) {
                countfourplus++;
                j += 3;
            }
            if (field[j][i] == -1 && field[j][i] == field[j + 1][i] && field[j + 1][i] == field[j + 2][i] && field[j + 2][i] == field[j + 3][i]) {
                countfourminus++;
                j += 3;
            }
        }
        return new int[]{countfourplus, countfourminus};

    }

    /**
     * Scans the targetarray and sets a preference value to the next empty cell.
     * This method finds a possible constellation of two,three or four equal merblas in a column.
     * Depending on the playerfalg it sets a positiv or negativ preference to the cell that would complet
     * the "fiveinarow"
     *

     * @param field targetarray
     * @param black playerflag
     */
    public static void searchPossibleFiveInAColumn(int[][] field, boolean black) {
        for (int i = 0; i < 6; i++) {
            if ((searchCoupleInAColumn(field, i)[0] == 2 && ((searchCoupleInAColumn(field, i)[1] == 0) && searchCoupleInAColumn(field, i)[2] < 2)) || (searchThreeInAColumn(field, i)[0] == 1 && ((searchThreeInAColumn(field, i)[1] == 0)))) {
                for (int j = 0; j < 4; j++) {
                    if (field[j][i] == 1 && field[j][i] == field[j + 2][i] && isEmpty(field[j + 1][i])) {
                        if (haveAPreference(field[j + 1][i])) {
                            field[j + 1][i] = Math.abs(3000 * field[j][i] * field[j + 1][i]) * colorToInt(black);
                        } else {
                            field[j + 1][i] += 3000 * field[j][i];
                        }
                    }
                }

            }

            if (searchFourInAColumn(field, i)[0] == 1) {
                for (int j = 0; j < 4; j++) {
                    if (field[j][i] == 1 && field[j + 1][i] == 1 && isEmpty(field[j + 2][i])) {
                        if (haveAPreference(field[j + 2][i])) {
                            field[j + 2][i] = Math.abs(3000 * field[j][i] * field[j + 2][i]) * colorToInt(black);
                        } else {
                            field[j + 2][i] += 3000 * field[j][i];
                        }

                    }
                    if (j - 1 > -1 && field[j][i] == 1 && field[j + 1][i] == 1 && isEmpty(field[j - 1][i])) {
                        if (haveAPreference(field[j - 1][i])) {
                            field[j - 1][i] = Math.abs(3000 * field[j][i] * field[j - 1][i]) * colorToInt(black);
                        } else {
                            field[j - 1][i] += 3000 * field[j][i];
                        }

                    }
                }
            }


            if ((searchCoupleInAColumn(field, i)[1] == 2 && ((searchCoupleInAColumn(field, i)[0] == 0) && searchCoupleInAColumn(field, i)[2] < 2)) || (searchThreeInAColumn(field, i)[1] == 1 && ((searchThreeInAColumn(field, i)[0] == 0)))) {
                for (int j = 0; j < 4; j++) {
                    if (field[j][i] == -1 && field[j][i] == field[j + 2][i] && isEmpty(field[j + 1][i])) {
                        if (haveAPreference(field[j + 1][i])) {
                            field[j + 1][i] = Math.abs(3000 * field[j][i] * field[j + 1][i]) * colorToInt(black);
                        } else {
                            field[j + 1][i] += 3000 * field[j][i];
                        }
                    }
                }
            }

            if (searchFourInAColumn(field, i)[1] == 1) {
                for (int j = 0; j < 4; j++) {
                    if (field[j][i] == -1 && field[j + 1][i] == -1 && isEmpty(field[j + 2][i])) {
                        if (haveAPreference(field[j + 2][i])) {
                            field[j + 2][i] = Math.abs(3000 * field[j][i] * field[j + 2][i]) * colorToInt(black);
                        } else {
                            field[j + 2][i] += 3000 * field[j][i];
                        }

                    }
                    if (j - 1 > -1 && field[j][i] == -1 && field[j + 1][i] == -1 && isEmpty(field[j - 1][i])) {
                        if (haveAPreference(field[j - 1][i])) {
                            field[j - 1][i] = Math.abs(3000 * field[j][i] * field[j - 1][i]) * colorToInt(black);
                        } else {
                            field[j - 1][i] += 3000 * field[j][i];
                        }

                    }
                }
            }
        }
    }

    /**
     * The ambition of this method is to find all couple of two equal neighbour
     * marbels in the main diagonal from the topleft corner to the underright corner
     *
     *
     * @param field target field
     * @return int[] the first element represent the number of +1 couples <br>
     *               the second  element represent the number of -1 couples <br>
     *               the third element represent the number of all other couples
     */
    public static int[] searchCoupleInADiagonal_TopLeft_Main(int[][] field) {
        int countcoupleminus = 0, countcoupleplus = 0, countemptycouple = 0;
        for (int j = 0; j < 5; j++) {
            if (field[j][j] == 1 && field[j][j] == field[j + 1][j + 1]) {
                countcoupleplus++;
                j++;
            }
            if (field[j][j] == -1 && field[j][j] == field[j + 1][j + 1]) {
                countcoupleminus++;
                j++;
            }
            if (isEmpty(field[j][j]) && isEmpty(field[j + 1][j + 1])) {
                countemptycouple++;
                j++;
            }
        }
        return new int[]{countcoupleplus, countcoupleminus, countemptycouple};
    }

    /**
     * The ambition of this method is to find all couple of two equal neighbour
     * marbels in the under and upper diagonal from the topleft corner to the underright corner
     *
     *
     * @param field targetfield
     * @param upper a flag to choose the diagonal upper the main or the diagonal under the main
     * @return int[] the first element represent the number of +1 couples<br>
     *               the second  element represent the number of -1 couples<br>
     *               the third element represent the number of all other couples
     */
    public static int[] searchCoupleInADiagonal_TopLeft_UnderUpperMain(int[][] field, boolean upper) {
        int x, y;
        int countcoupleminus = 0, countcoupleplus = 0, countemptycouple = 0;
        if (upper) {
            x = 1;
            y = 0;
        } else {
            y = 1;
            x = 0;
        }

        for (int j = 0; j < 4; j++) {
            if (field[j + y][j + x] == 1 && field[j + y][j + x] == field[j + 1 + y][j + 1 + x]) {
                countcoupleplus++;
                j++;
            }
            if (field[j + y][j + x] == -1 && field[j + y][j + x] == field[j + 1 + y][j + 1 + x]) {
                countcoupleminus++;
                j++;
            }
            if (isEmpty(field[j + y][j + x]) && isEmpty(field[j + 1 + y][j + 1 + x])) {
                countemptycouple++;
                j++;
            }
        }
        return new int[]{countcoupleplus, countcoupleminus, countemptycouple};
    }

    /**
     * The ambition of this method is to find all sequence of three equal neighbour marbels 
     * in the main diagonal from the topleft corner to the underright corner
     *
     *
     * @param field target field
     * @return new int[]{countcoupleplus, countcoupleminus}
     *                      the first element represent the number of +1 couples<br>
     *                      the second  element represent the number of -1 couples
     */
    public static int[] searchThreeInADiagonal_TopLeft_Main(int[][] field) {
        int countcoupleminus = 0, countcoupleplus = 0;
        for (int j = 0; j < 4; j++) {
            if (field[j][j] == 1 && field[j][j] == field[j + 1][j + 1] && field[j + 1][j + 1] == field[j + 2][j + 2]) {
                countcoupleplus++;
                j += 2;
            }
            if (field[j][j] == -1 && field[j][j] == field[j + 1][j + 1] && field[j + 1][j + 1] == field[j + 2][j + 2]) {
                countcoupleminus++;
                j += 2;
            }

        }
        return new int[]{countcoupleplus, countcoupleminus};


    }

    /**
     *
     * The ambition of this method is to find all sequence of three equal neighbour marbels
     * in the diagnals upper and under the main diagonal from the topleft corner to the underright corner
     *
     * @param upper flag to choose between the upper diagnal and the under one
     * @param field targetfield
     * @return new int[]{countcoupleplus, countcoupleminus}
     *                      the first element represent the number of +1 couples<br>
     *                      the second  element represent the number of -1 couples
     */
    public static int[] searchThreeInADiagonal_TopLeft_UnderUpperMain(int[][] field, boolean upper) {
        int x, y;
        int countcoupleminus = 0, countcoupleplus = 0;
        if (upper) {
            x = 1;
            y = 0;
        } else {
            y = 1;
            x = 0;
        }
        for (int j = 0; j < 3; j++) {
            if (field[j + y][j + x] == 1 && field[j + y][j + x] == field[j + 1 + y][j + 1 + x] && field[j + 1 + y][j + 1 + x] == field[j + 2 + y][j + 2 + x]) {
                countcoupleplus++;
                j += 2;
            }
            if (field[j + y][j + x] == -1 && field[j + y][j + x] == field[j + 1 + y][j + 1 + x] && field[j + 1 + y][j + 1 + x] == field[j + 2 + y][j + 2 + x]) {
                countcoupleminus++;
                j += 2;
            }

        }
        return new int[]{countcoupleplus, countcoupleminus};
    }

    /**
     * The ambition of this method is to find all sequence of four equal neighbour marbels
     * in the main diagonal from the topleft corner to the underright corner
     *
     *
     * @param field targetfield
     * @return new int[]{countcoupleplus, countcoupleminus}
     *                      the first element represent the number of +1 couples<br>
     *                      the second  element represent the number of -1 couples
     */
    public static int[] searchFourInADiagonal_TopLeft_Main(int[][] field) {
        int countcoupleminus = 0, countcoupleplus = 0;
        for (int j = 0; j < 3; j++) {
            if (field[j][j] == 1 && field[j][j] == field[j + 1][j + 1] && field[j + 1][j + 1] == field[j + 2][j + 2] && field[j + 2][j + 2] == field[j + 3][j + 3]) {
                countcoupleplus++;
                j += 3;
            }
            if (field[j][j] == -1 && field[j][j] == field[j + 1][j + 1] && field[j + 1][j + 1] == field[j + 2][j + 2] && field[j + 2][j + 2] == field[j + 3][j + 3]) {
                countcoupleminus++;
                j += 3;
            }

        }
        return new int[]{countcoupleplus, countcoupleminus};
    }

    /**
     *
     * The ambition of this method is to find all sequence of four equal neighbour marbels
     * in the upper and under diagonal from the topleft corner to the underright corner
     *
     * @param upper flag to choose between the upper diagnal and the under one
     * @param field target field
     * @return new int[]{countcoupleplus, countcoupleminus}
     *                      the first element represent the number of +1 couples<br>
     *                      the second  element represent the number of -1 couples
     */
    public static int[] searchFourInADiagonal_TopLeft_UnderUpperMain(int[][] field, boolean upper) {
        int x, y;
        int countcoupleminus = 0, countcoupleplus = 0;
        if (upper) {
            x = 1;
            y = 0;
        } else {
            y = 1;
            x = 0;
        }
        for (int j = 0; j < 2; j++) {
            if (field[j + y][j + x] == 1 && field[j + y][j + x] == field[j + 1 + y][j + 1 + x] && field[j + 1 + y][j + 1 + x] == field[j + 2 + y][j + 2 + x] && field[j + 2 + y][j + 2 + x] == field[j + 3 + y][j + 3 + x]) {
                countcoupleplus++;
                j += 3;
            }
            if (field[j + y][j + x] == -1 && field[j + y][j + x] == field[j + 1 + y][j + 1 + x] && field[j + 1 + y][j + 1 + x] == field[j + 2 + y][j + 2 + x] && field[j + 2 + y][j + 2 + x] == field[j + 3 + y][j + 3 + x]) {
                countcoupleminus++;
                j += 3;
            }

        }
        return new int[]{countcoupleplus, countcoupleminus};
    }

    /**
     * Scans the targetarray and sets a preference value to the next empty cell.
     * This method finds a possible constellation of two,three or four equal merblas in a the "topleft" diagnal.
     * Depending on the playerfalg it sets a positiv or negativ preference to the cell that would complet
     * the "fiveinarow"
     *

     * @param field targetarray
     * @param black playerflag
     */
    public static void searchPossibleFiveInADiagonal_TopLeft(int[][] field, boolean black) {

        if ((searchCoupleInADiagonal_TopLeft_Main(field)[0] == 2 && ((searchCoupleInADiagonal_TopLeft_Main(field)[1] == 0) && searchCoupleInADiagonal_TopLeft_Main(field)[2] < 2)) || (searchThreeInADiagonal_TopLeft_Main(field)[0] == 1 && ((searchThreeInADiagonal_TopLeft_Main(field)[1] == 0)))) {
            for (int j = 0; j < 4; j++) {
                if (field[j][j] == 1 && field[j][j] == field[j + 2][j + 2] && isEmpty(field[j + 1][j + 1])) {
                    if (haveAPreference(field[j + 1][j + 1])) {
                        field[j + 1][j + 1] = Math.abs(3000 * field[j][j] * field[j + 1][j + 1]) * colorToInt(black);
                    } else {
                        field[j + 1][j + 1] += 3000 * field[j][j];
                    }
                }
            }
        }

        if ((searchCoupleInADiagonal_TopLeft_Main(field)[1] == 2 && ((searchCoupleInADiagonal_TopLeft_Main(field)[0] == 0) && searchCoupleInADiagonal_TopLeft_Main(field)[2] < 2)) || (searchThreeInADiagonal_TopLeft_Main(field)[1] == 1 && ((searchThreeInADiagonal_TopLeft_Main(field)[0] == 0)))) {
            for (int j = 0; j < 4; j++) {
                if (field[j][j] == -1 && field[j][j] == field[j + 2][j + 2] && isEmpty(field[j + 1][j + 1])) {
                    if (haveAPreference(field[j + 1][j + 1])) {
                        field[j + 1][j + 1] = Math.abs(3000 * field[j][j] * field[j + 1][j + 1]) * colorToInt(black);
                    } else {
                        field[j + 1][j + 1] += 3000 * field[j][j];
                    }
                }
            }
        }

        if (searchFourInADiagonal_TopLeft_Main(field)[0] == 1) {
            for (int j = 0; j < 4; j++) {
                if (field[j][j] == 1 && field[j + 1][j + 1] == 1 && isEmpty(field[j + 2][j + 2])) {
                    if (haveAPreference(field[j + 2][j + 2])) {
                        field[j + 2][j + 2] = Math.abs(3000 * field[j][j] * field[j + 2][j + 2]) * colorToInt(black);
                    } else {
                        field[j + 2][j + 2] += 3000 * field[j][j];
                    }

                }
                if (j - 1 > -1 && field[j][j] == 1 && field[j + 1][j + 1] == 1 && isEmpty(field[j - 1][j - 1])) {
                    if (haveAPreference(field[j - 1][j - 1])) {
                        field[j - 1][j - 1] = Math.abs(3000 * field[j][j] * field[j - 1][j - 1]) * colorToInt(black);
                    } else {
                        field[j - 1][j - 1] += 3000 * field[j][j];
                    }

                }
            }
        }

        if (searchFourInADiagonal_TopLeft_Main(field)[1] == 1) {
            for (int j = 0; j < 4; j++) {
                if (field[j][j] == -1 && field[j + 1][j + 1] == -1 && isEmpty(field[j + 2][j + 2])) {
                    if (haveAPreference(field[j + 2][j + 2])) {
                        field[j + 2][j + 2] = Math.abs(3000 * field[j][j] * field[j + 2][j + 2]) * colorToInt(black);
                    } else {
                        field[j + 2][j + 2] += 3000 * field[j][j];
                    }

                }
                if (j - 1 > -1 && field[j][j] == -1 && field[j + 1][j + 1] == -1 && isEmpty(field[j - 1][j - 1])) {
                    if (haveAPreference(field[j - 1][j - 1])) {
                        field[j - 1][j - 1] = Math.abs(3000 * field[j][j] * field[j - 1][j - 1]) * colorToInt(black);
                    } else {
                        field[j - 1][j - 1] += 3000 * field[j][j];
                    }

                }
            }
        }




    }

    /**
     * Scans the targetarray and sets a preference value to the next empty cell.
     * This method finds a possible constellation of two,three or four equal merblas in a diagnal over or under the "topleft" diagnal.
     * Depending on the playerfalg it sets a positiv or negativ preference to the cell that would complet
     * the "fiveinarow".
     * The preference values will be set on the array.
     *
     *
     * @param field targetarray
     * @param black playerflag
     */
    public static void searchPossibleFiveInADiagonal_TopLeft_UnderUpperMain(int[][] field, boolean black) {
        if ((searchCoupleInADiagonal_TopLeft_UnderUpperMain(field, true)[0] == 2 && ((searchCoupleInADiagonal_TopLeft_UnderUpperMain(field, true)[1] == 0))) || (searchThreeInADiagonal_TopLeft_UnderUpperMain(field, true)[0] == 1 && ((searchThreeInADiagonal_TopLeft_UnderUpperMain(field, true)[1] == 0)))) {

            for (int j = 0; j < 3; j++) {
                if (field[j][j + 1] == 1 && field[j][j + 1] == field[j + 2][j + 3] && isEmpty(field[j + 1][j + 2])) {
                    if (haveAPreference(field[j + 1][j + 2])) {
                        field[j + 1][j + 2] = Math.abs(3000 * field[j][j + 1] * field[j + 1][j + 2]) * colorToInt(black);
                    } else {
                        field[j + 1][j + 2] += 3000 * field[j][j + 1];
                    }
                }
            }
        }

        if ((searchCoupleInADiagonal_TopLeft_UnderUpperMain(field, false)[0] == 2 && ((searchCoupleInADiagonal_TopLeft_UnderUpperMain(field, false)[1] == 0))) || (searchThreeInADiagonal_TopLeft_UnderUpperMain(field, false)[0] == 1 && ((searchThreeInADiagonal_TopLeft_UnderUpperMain(field, false)[1] == 0)))) {

            for (int j = 0; j < 3; j++) {
                if ((j - 1 > -1) && field[j][j - 1] == 1 && field[j][j - 1] == field[j + 2][j + 1] && isEmpty(field[j + 1][j])) {
                    if (haveAPreference(field[j + 1][j])) {
                        field[j + 1][j] = Math.abs(3000 * field[j][j - 1] * field[j + 1][j]) * colorToInt(black);
                    } else {
                        field[j + 1][j] += 3000 * field[j][j - 1];
                    }
                }
            }
        }

        if ((searchCoupleInADiagonal_TopLeft_UnderUpperMain(field, true)[1] == 2 && ((searchCoupleInADiagonal_TopLeft_UnderUpperMain(field, true)[0] == 0))) || (searchThreeInADiagonal_TopLeft_UnderUpperMain(field, true)[1] == 1 && ((searchThreeInADiagonal_TopLeft_UnderUpperMain(field, true)[0] == 0)))) {

            for (int j = 0; j < 3; j++) {
                if (field[j][j + 1] == -1 && field[j][j + 1] == field[j + 2][j + 3] && isEmpty(field[j + 1][j + 2])) {
                    if (haveAPreference(field[j + 1][j + 2])) {
                        field[j + 1][j + 2] = Math.abs(3000 * field[j][j + 1] * field[j + 1][j + 2]) * colorToInt(black);
                    } else {
                        field[j + 1][j + 2] += 3000 * field[j][j + 1];
                    }
                }
            }
        }

        if ((searchCoupleInADiagonal_TopLeft_UnderUpperMain(field, false)[1] == 2 && ((searchCoupleInADiagonal_TopLeft_UnderUpperMain(field, false)[0] == 0))) || (searchThreeInADiagonal_TopLeft_UnderUpperMain(field, false)[1] == 1 && ((searchThreeInADiagonal_TopLeft_UnderUpperMain(field, false)[0] == 0)))) {

            for (int j = 0; j < 3; j++) {
                if ((j - 1 > -1) && field[j][j - 1] == -1 && field[j][j - 1] == field[j + 2][j + 1] && isEmpty(field[j + 1][j])) {
                    if (haveAPreference(field[j + 1][j])) {
                        field[j + 1][j] = Math.abs(3000 * field[j][j - 1] * field[j + 1][j]) * colorToInt(black);
                    } else {
                        field[j + 1][j] += 3000 * field[j][j - 1];
                    }
                }
            }
        }

        if (searchFourInADiagonal_TopLeft_UnderUpperMain(field, true)[0] == 1) {

            if (field[1][2] == 1 && isEmpty(field[0][1])) {
                if (haveAPreference(field[0][1])) {
                    field[0][1] = Math.abs(3000 * field[1][2] * field[0][1]) * colorToInt(black);
                } else {
                    field[0][1] += 3000 * field[1][2];
                }
            } else if (field[1][2] == 1 && isEmpty(field[4][5])) {
                if (haveAPreference(field[4][5])) {
                    field[4][5] = Math.abs(3000 * field[1][2] * field[4][5]) * colorToInt(black);
                } else {
                    field[4][5] += 3000 * field[1][2];
                }

            }

        }


        if (searchFourInADiagonal_TopLeft_UnderUpperMain(field, false)[0] == 1) {

            if (field[2][1] == 1 && isEmpty(field[1][0])) {
                if (haveAPreference(field[1][0])) {
                    field[1][0] = Math.abs(3000 * field[2][1] * field[1][0]) * colorToInt(black);
                } else {
                    field[1][0] += 3000 * field[2][1];
                }
            } else if (field[2][1] == 1 && isEmpty(field[5][4])) {
                if (haveAPreference(field[5][4])) {
                    field[5][4] = Math.abs(3000 * field[2][1] * field[5][4]) * colorToInt(black);
                } else {
                    field[5][4] += 3000 * field[2][1];
                }

            }

        }

        if (searchFourInADiagonal_TopLeft_UnderUpperMain(field, true)[1] == 1) {

            if (field[1][2] == -1 && isEmpty(field[0][1])) {
                if (haveAPreference(field[0][1])) {
                    field[0][1] = Math.abs(3000 * field[1][2] * field[0][1]) * colorToInt(black);
                } else {
                    field[0][1] += 3000 * field[1][2];
                }
            } else if (field[1][2] == -1 && isEmpty(field[4][5])) {
                if (haveAPreference(field[4][5])) {
                    field[4][5] = Math.abs(3000 * field[1][2] * field[4][5]) * colorToInt(black);
                } else {
                    field[4][5] += 3000 * field[1][2];
                }

            }

        }


        if (searchFourInADiagonal_TopLeft_UnderUpperMain(field, false)[1] == 1) {

            if (field[2][1] == -1 && isEmpty(field[1][0])) {
                if (haveAPreference(field[1][0])) {
                    field[1][0] = Math.abs(3000 * field[2][1] * field[1][0]) * colorToInt(black);
                } else {
                    field[1][0] += 3000 * field[2][1];
                }
            } else if (field[2][1] == -1 && isEmpty(field[5][4])) {
                if (haveAPreference(field[5][4])) {
                    field[5][4] = Math.abs(3000 * field[2][1] * field[5][4]) * colorToInt(black);
                } else {
                    field[5][4] += 3000 * field[2][1];
                }

            }

        }

    }

    /**
     * The ambition of this method is to find all couple of two equal neighbour
     * marbels in the main diagonal from the under left corner to the upper right corner
     *
     *
     * @param field targetfield
     * @return int[] the first element represent the number of +1 couples<br>
     *               the second  element represent the number of -1 couples<br>
     *               the third element represent the number of all other couples
     */
    public static int[] searchCoupleInADiagonal_BelowLeft_Main(int[][] field) {
        int countcoupleminus = 0, countcoupleplus = 0, countemptycouple = 0;
        for (int i = 5, j = 0; i > 0 && j < 6; i--, j++) {
            if ((field[i][j]) == 1 && (field[i][j] == field[i - 1][j + 1])) {
                countcoupleplus++;
                j++;
                i--;
            }

            if ((field[i][j]) == -1 && (field[i][j] == field[i - 1][j + 1])) {
                countcoupleminus++;
                j++;
                i--;
            }

            if (isEmpty(field[i][j]) && isEmpty(field[i - 1][j + 1])) {
                countemptycouple++;
                j++;
                i--;
            }
        }



        return new int[]{countcoupleplus, countcoupleminus, countemptycouple};

    }

    /**
     * The ambition of this method is to find all couple of two equal neighbour
     * marbels in the under and upper diagonal from the under left corner to the upper right corner
     *
     *
     * @param field target field
     * @param upper a flag to choose the diagonal upper the main or the diagonal under the main
     * @return int[] the first element represent the number of +1 couples<br>
     *               the second  element represent the number of -1 couples<br>
     *               the third element represent the number of all other couples
     */
    public static int[] searchCoupleInADiagonal_BelowLeft_UnderUpperMain(int[][] field, boolean upper) {
        int x, y;
        int countcoupleminus = 0, countcoupleplus = 0, countemptycouple = 0;
        if (upper) {
            x = 1;
            y = 0;
        } else {
            y = 1;
            x = 0;
        }
        for (int i = 5, j = 0; i > 1 && j < 5; i--, j++) {
            if ((field[i - x][j + y]) == 1 && (field[i - x][j + y] == field[i - x - 1][j + y + 1])) {
                countcoupleplus++;
                j++;
                i--;
            }

            if ((field[i - x][j + y]) == -1 && (field[i - x][j + y] == field[i - x - 1][j + y + 1])) {
                countcoupleminus++;
                j++;
                i--;
            }

            if (isEmpty(field[i - x][j + y]) && isEmpty(field[i - x - 1][j + y + 1])) {
                countemptycouple++;
                j++;
                i--;
            }
        }

        return new int[]{countcoupleplus, countcoupleminus, countemptycouple};
    }

    /**
     * The ambition of this method is to find all sequences of three equal neighbour
     * marbels in the main diagonal from the under left corner to the upper right corner
     *
     *
     * @param field target field
     * @return int[] the first element represent the number of +1 couples<br>
     *               the second  element represent the number of -1 couples
     *
     */
    public static int[] searchThreeInADiagonal_BelowLeft_Main(int[][] field) {
        int countcoupleminus = 0, countcoupleplus = 0;
        for (int i = 5, j = 0; i > 0 && j < 4; i--, j++) {
            if ((field[i][j]) == 1 && field[i][j] == field[i - 1][j + 1] && field[i - 1][j + 1] == field[i - 2][j + 2]) {
                countcoupleplus++;
                j += 2;
                i -= 2;

            }
            if ((field[i][j]) == -1 && field[i][j] == field[i - 1][j + 1] && field[i - 1][j + 1] == field[i - 2][j + 2]) {
                countcoupleminus++;
                j += 2;
                i -= 2;
            }

        }
        return new int[]{countcoupleplus, countcoupleminus};
    }

    /**
     * The ambition of this method is to find all sequences of three equal neighbour
     * marbels in the under diagonal and upper diagonal from the under left corner to the upper right corner
     *
     *
     * @param field target field
     * @param upper a flag to choose the diagonal upper the main or the diagonal under the main
     * @return int[] the first element represent the number of +1 couples
     *               the second  element represent the number of -1 couples
     *               the third element represent the number of all other couples
     */
    public static int[] searchThreeInADiagonal_BelowLeft_UnderUpperMain(int[][] field, boolean upper) {
        int x, y;
        int countcoupleminus = 0, countcoupleplus = 0;
        if (upper) {
            x = 1;
            y = 0;
        } else {
            y = 1;
            x = 0;
        }
        for (int i = 5, j = 0; i > 2 && j < 4; i--, j++) {
            if ((field[i - x][j + y]) == 1 && (field[i - x][j + y] == field[i - x - 1][j + y + 1]) && field[i - x - 1][j + y + 1] == field[i - x - 2][j + y + 2]) {
                countcoupleplus++;
                j += 2;
                i -= 2;

            }

            if ((field[i - x][j + y]) == -1 && (field[i - x][j + y] == field[i - x - 1][j + y + 1]) && field[i - x - 1][j + y + 1] == field[i - x - 2][j + y + 2]) {
                countcoupleminus++;
                j += 2;
                i -= 2;

            }
        }


        return new int[]{countcoupleplus, countcoupleminus};
    }

    /**
     * The ambition of this method is to find all sequences of four equal neighbour
     * marbels in the main diagonal from the under left corner to the upper right corner
     *
     *
     * @param field targetfield
     * @return int[] the first element represent the number of +1 couples<br>
     *               the second  element represent the number of -1 couples
     *
     */
    public static int[] searchFourInADiagonal_BelowLeft_Main(int[][] field) {
        int countcoupleminus = 0, countcoupleplus = 0;
        for (int i = 5, j = 0; i > 0 && j < 3; i--, j++) {
            if ((field[i][j]) == 1 && field[i][j] == field[i - 1][j + 1] && field[i - 1][j + 1] == field[i - 2][j + 2] && field[i - 2][j + 2] == field[i - 3][j + 3]) {
                countcoupleplus++;
                j += 3;
                i -= 3;

            }
            if ((field[i][j]) == -1 && field[i][j] == field[i - 1][j + 1] && field[i - 1][j + 1] == field[i - 2][j + 2] && field[i - 2][j + 2] == field[i - 3][j + 3]) {
                countcoupleminus++;
                j += 3;
                i -= 3;
            }

        }
        return new int[]{countcoupleplus, countcoupleminus};
    }

    /**
     * The ambition of this method is to find all sequences of four equal neighbour
     * marbels in the under main diagonal and upper main diagonal from the under left corner to the upper right corner
     *
     *
     * @param field targetfield
     * @param upper a flag to choose the diagonal upper the main or the diagonal under the main
     * @return int[] the first element represent the number of +1 couples<br>
     *               the second  element represent the number of -1 couples<br>
     *               the third element represent the number of all other couples
     */
    public static int[] searchFourInADiagonal_BelowLeft_UnderUpperMain(int[][] field, boolean upper) {
        int x, y;
        int countcoupleminus = 0, countcoupleplus = 0;
        if (upper) {
            x = 1;
            y = 0;
        } else {
            y = 1;
            x = 0;
        }

        for (int i = 5, j = 0; i > 0 && j < 2; i--, j++) {
            if ((field[i - x][j + y]) == 1 && (field[i - x][j + y] == field[i - x - 1][j + y + 1]) && field[i - x - 1][j + y + 1] == field[i - x - 2][j + y + 2] && field[i - x - 2][j + y + 2] == field[i - x - 3][j + y + 3]) {
                countcoupleplus++;
                j += 3;
                i -= 3;

            }

            if ((field[i - x][j + y]) == -1 && (field[i - x][j + y] == field[i - x - 1][j + y + 1]) && field[i - x - 1][j + y + 1] == field[i - x - 2][j + y + 2] && field[i - x - 2][j + y + 2] == field[i - x - 3][j + y + 3]) {
                countcoupleminus++;
                j += 3;
                i -= 3;
            }
        }
        return new int[]{countcoupleplus, countcoupleminus};
    }

    /**
     * Scans the targetarray and sets a preference value to the next empty cell.
     * This method finds a possible constellation of two,three or four equal merblas in a diagnal from the under left corner to the upper right corner.
     * Depending on the playerfalg it sets a positiv or negativ preference to the cell that would complet
     * the "fiveinarow".
     * The preference values will be set on the array.
     *
     *
     * @param field target array
     * @param black player flag
     */
    public static void searchPossibleFiveInADiagonal_BelowLeft(int[][] field, boolean black) {
        if ((searchCoupleInADiagonal_BelowLeft_Main(field)[0] == 2 && ((searchCoupleInADiagonal_BelowLeft_Main(field)[1] == 0) && searchCoupleInADiagonal_BelowLeft_Main(field)[2] < 2)) || (searchThreeInADiagonal_BelowLeft_Main(field)[0] == 1 && ((searchThreeInADiagonal_BelowLeft_Main(field)[1] == 0)))) {

            for (int i = 5, j = 0; i > 0 && j < 4; i--, j++) {
                if (field[i][j] == 1 && field[i][j] == field[i - 2][j + 2] && isEmpty(field[i - 1][j + 1])) {
                    if (haveAPreference(field[i - 1][j + 1])) {
                        field[i - 1][j + 1] = Math.abs(3000 * field[i][j] * field[i - 1][j + 1]) * colorToInt(black);
                    } else {
                        field[i - 1][j + 1] += 3000 * field[i][j];
                    }
                }

            }
        }

        if ((searchCoupleInADiagonal_BelowLeft_Main(field)[1] == 2 && ((searchCoupleInADiagonal_BelowLeft_Main(field)[0] == 0) && searchCoupleInADiagonal_BelowLeft_Main(field)[2] < 2)) || (searchThreeInADiagonal_BelowLeft_Main(field)[1] == 1 && ((searchThreeInADiagonal_BelowLeft_Main(field)[0] == 0)))) {
            for (int i = 5, j = 0; i > 0 && j < 4; i--, j++) {
                if (field[i][j] == -1 && field[i][j] == field[i - 2][j + 2] && isEmpty(field[i - 1][j + 1])) {
                    if (haveAPreference(field[i - 1][j + 1])) {
                        field[i - 1][j + 1] = Math.abs(3000 * field[i][j] * field[i - 1][j + 1]) * colorToInt(black);
                    } else {
                        field[i - 1][j + 1] += 3000 * field[i][j];
                    }
                }

            }
        }

        if (searchFourInADiagonal_BelowLeft_Main(field)[0] == 1) {
            for (int i = 5, j = 0; i > 0 && j < 4; i--, j++) {
                if (field[i][j] == 1 && field[i - 1][j + 1] == 1 && isEmpty(field[i - 2][j + 2])) {
                    if (haveAPreference(field[i - 2][j + 2])) {
                        field[i - 2][j + 2] = Math.abs(3000 * field[i][j] * field[i - 2][j + 2]) * colorToInt(black);
                    } else {
                        field[i - 2][j + 2] += 3000 * field[i][j];
                    }
                }

                if (i + 1 < 6 && j - 1 > -1 && field[i][j] == 1 && field[i - 1][j + 1] == 1 && isEmpty(field[i + 1][j - 1])) {
                    if (haveAPreference(field[i + 1][j - 1])) {
                        field[i + 1][j - 1] = Math.abs(3000 * field[i][j] * field[i + 1][j - 1]) * colorToInt(black);
                    } else {
                        field[i + 1][j - 1] += 3000 * field[i][j];
                    }

                }
            }
        }

        if (searchFourInADiagonal_BelowLeft_Main(field)[1] == 1) {
            for (int i = 5, j = 1; i > 0 && j < 4; i--, j++) {
                if (field[i][j] == -1 && field[i - 1][j + 1] == -1 && isEmpty(field[i - 2][j + 2])) {
                    if (haveAPreference(field[i - 2][j + 2])) {
                        field[i - 2][j + 2] = Math.abs(3000 * field[i][j] * field[i - 2][j + 2]) * colorToInt(black);
                    } else {
                        field[i - 2][j + 2] += 3000 * field[i][j];
                    }
                }

                if (i + 1 < 6 && j - 1 > -1 && field[i][j] == -1 && field[i + 1][j + 1] == -1 && isEmpty(field[i + 1][j - 1])) {
                    if (haveAPreference(field[i + 1][j - 1])) {
                        field[i + 1][j - 1] = Math.abs(3000 * field[i][j] * field[i + 1][j - 1]) * colorToInt(black);
                    } else {
                        field[i + 1][j - 1] += 3000 * field[i][j];
                    }

                }
            }
        }

    }

    /**
     * Scans the targetarray and sets a preference value to the next empty cell.
     * This method finds a possible constellation of two,three or four equal merblas in a diagnal over or under the "belowleft" diagnal.
     * Depending on the playerfalg it sets a positiv or negativ preference to the cell that would complet
     * the "fiveinainadiagonal".
     * The preference values will be set on the array.
     *
     * @param field targetarray
     * @param black playerflag
     */
    public static void searchPossibleFiveInADiagonal_BelowLeft_UnderUpperMain(int[][] field, boolean black) {
        if ((searchCoupleInADiagonal_BelowLeft_UnderUpperMain(field, true)[0] == 2 && ((searchCoupleInADiagonal_BelowLeft_UnderUpperMain(field, true)[1] == 0))) || (searchThreeInADiagonal_BelowLeft_UnderUpperMain(field, true)[0] == 1 && ((searchThreeInADiagonal_BelowLeft_UnderUpperMain(field, true)[1] == 0)))) {
            for (int i = 5, j = 0; i > 2 && j < 4; i--, j++) {
                if (field[i - 1][j] == 1 && field[i - 1][j] == field[i - 3][j + 2] && isEmpty(field[i - 2][j + 1])) {
                    if (haveAPreference(field[i - 2][j + 1])) {
                        field[i - 2][j + 1] = Math.abs(3000 * field[i - 1][j] * field[i - 2][j + 1]) * colorToInt(black);
                    } else {
                        field[i - 2][j + 1] += 3000 * field[i - 1][j];
                    }
                }

            }
        }

        if ((searchCoupleInADiagonal_BelowLeft_UnderUpperMain(field, false)[0] == 2 && ((searchCoupleInADiagonal_BelowLeft_UnderUpperMain(field, false)[1] == 0))) || (searchThreeInADiagonal_BelowLeft_UnderUpperMain(field, false)[0] == 1 && ((searchThreeInADiagonal_BelowLeft_UnderUpperMain(field, false)[1] == 0)))) {
            for (int i = 5, j = 0; i > 2 && j < 4; i--, j++) {
                if (field[i][j + 1] == 1 && field[i][j + 1] == field[i - 2][j + 3] && isEmpty(field[i - 1][j + 2])) {
                    if (haveAPreference(field[i - 1][j + 2])) {
                        field[i - 1][j + 2] = Math.abs(3000 * field[i][j + 1] * field[i - 1][j + 2]) * colorToInt(black);
                    } else {
                        field[i - 1][j + 2] += 3000 * field[i][j + 1];
                    }
                }
            }
        }


        if ((searchCoupleInADiagonal_BelowLeft_UnderUpperMain(field, true)[1] == 2 && ((searchCoupleInADiagonal_BelowLeft_UnderUpperMain(field, true)[0] == 0))) || (searchThreeInADiagonal_BelowLeft_UnderUpperMain(field, true)[1] == 1 && ((searchThreeInADiagonal_BelowLeft_UnderUpperMain(field, true)[0] == 0)))) {
            for (int i = 5, j = 0; i > 2 && j < 4; i--, j++) {
                if (field[i - 1][j] == 1 && field[i - 1][j] == field[i - 3][j + 2] && isEmpty(field[i - 2][j + 1])) {
                    if (haveAPreference(field[i - 2][j + 1])) {
                        field[i - 2][j + 1] = Math.abs(3000 * field[i - 1][j] * field[i - 2][j + 1]) * colorToInt(black);
                    } else {
                        field[i - 2][j + 1] += 3000 * field[i - 1][j];
                    }
                }

            }
        }

        if ((searchCoupleInADiagonal_BelowLeft_UnderUpperMain(field, false)[1] == 2 && ((searchCoupleInADiagonal_BelowLeft_UnderUpperMain(field, false)[0] == 0))) || (searchThreeInADiagonal_BelowLeft_UnderUpperMain(field, false)[1] == 1 && ((searchThreeInADiagonal_BelowLeft_UnderUpperMain(field, false)[0] == 0)))) {
            for (int i = 5, j = 0; i > 2 && j < 4; i--, j++) {
                if (field[i][j + 1] == 1 && field[i][j + 1] == field[i - 2][j + 3] && isEmpty(field[i - 1][j + 2])) {
                    if (haveAPreference(field[i - 1][j + 2])) {
                        field[i - 1][j + 2] = Math.abs(3000 * field[i][j + 1] * field[i - 1][j + 2]) * colorToInt(black);
                    } else {
                        field[i - 1][j + 2] += 3000 * field[i][j + 1];
                    }
                }
            }
        }


        if (searchFourInADiagonal_BelowLeft_UnderUpperMain(field, true)[0] == 1) {
            if (field[3][1] == 1 && isEmpty(field[4][0])) {
                if (haveAPreference(field[4][1])) {
                    field[4][1] = Math.abs(3000 * field[3][1] * field[4][1]) * colorToInt(black);
                } else {
                    field[4][1] += 3000 * field[3][1];
                }
            } else if (field[3][1] == 1 && isEmpty(field[0][4])) {
                if (haveAPreference(field[0][4])) {
                    field[0][4] = Math.abs(3000 * field[3][1] * field[0][4]) * colorToInt(black);
                } else {
                    field[0][4] += 3000 * field[3][1];
                }

            }


        }

        if (searchFourInADiagonal_BelowLeft_UnderUpperMain(field, false)[0] == 1) {
            if (field[4][2] == 1 && isEmpty(field[5][1])) {
                if (haveAPreference(field[5][1])) {
                    field[5][1] = Math.abs(3000 * field[4][2] * field[5][1]) * colorToInt(black);
                } else {
                    field[5][1] += 3000 * field[4][2];
                }
            } else if (field[4][2] == 1 && isEmpty(field[0][4])) {
                if (haveAPreference(field[1][5])) {
                    field[1][5] = Math.abs(3000 * field[4][2] * field[1][5]) * colorToInt(black);
                } else {
                    field[1][5] += 3000 * field[4][2];
                }

            }


        }

        if (searchFourInADiagonal_BelowLeft_UnderUpperMain(field, true)[1] == 1) {
            if (field[3][1] == -1 && isEmpty(field[4][0])) {
                if (haveAPreference(field[4][1])) {
                    field[4][1] = Math.abs(3000 * field[3][1] * field[4][1]) * colorToInt(black);
                } else {
                    field[4][1] += 3000 * field[3][1];
                }
            } else if (field[3][1] == -1 && isEmpty(field[0][4])) {
                if (haveAPreference(field[0][4])) {
                    field[0][4] = Math.abs(3000 * field[3][1] * field[0][4]) * colorToInt(black);
                } else {
                    field[0][4] += 3000 * field[3][1];
                }

            }


        }

        if (searchFourInADiagonal_BelowLeft_UnderUpperMain(field, false)[1] == 1) {
            if (field[4][2] == -1 && isEmpty(field[5][1])) {
                if (haveAPreference(field[5][1])) {
                    field[5][1] = Math.abs(3000 * field[4][2] * field[5][1]) * colorToInt(black);
                } else {
                    field[5][1] += 3000 * field[4][2];
                }
            } else if (field[4][2] == -1 && isEmpty(field[0][4])) {
                if (haveAPreference(field[1][5])) {
                    field[1][5] = Math.abs(3000 * field[4][2] * field[1][5]) * colorToInt(black);
                } else {
                    field[1][5] += 3000 * field[4][2];
                }
            }
        }

    }

    /**
     * A modified version of the rotate method from the GameEngine.Board
     * 
     * see GameEngine.Board.rotate
     *
     * @param board current array
     * @param quadrant which is supposed to be rotated
     * @param clock true for a right rotation, false for a left retation
     * @return new rotated board
     */
    public static int[][] rotate(int[][] board, int quadrant, int clock) {
        int[][] tempboard = new int[3][3];
        int[][] tempfield = new int[6][6];

        int fixx = 0;
        int fixy = 0;
        switch (quadrant) {
            case 1: {
                fixy = 1;
                fixx = 1;
            }
            break;
            case 2: {
                fixy = 1;
                fixx = 4;
            }
            break;
            case 3: {
                fixy = 4;
                fixx = 1;
            }
            break;
            case 4: {
                fixy = 4;
                fixx = 4;
            }
            break;
        }

        int fix = (fixy * 6) + fixx;
        int j = 5;
        int ver = 0, hor = 0;

        for (int i = 0; i <= 2; i++, j++) {
            ver = (fix + (j * clock)) / 6;
            hor = (fix + (j * clock)) % 6;
            tempboard[i][0] = board[ver][hor];
        }
        j = -1;

        for (int i = 0; i <= 2; i++, j++) {
            ver = (fix + (j * clock)) / 6;
            hor = (fix + (j * clock)) % 6;
            tempboard[i][1] = board[ver][hor];
        }
        j = 7;

        for (int i = 0; i <= 2; i++, j--) {
            ver = (fix - (j * clock)) / 6;
            hor = (fix - (j * clock)) % 6;
            tempboard[i][2] = board[ver][hor];
        }


        int next = fix - 7;
        for (int i = 0; i <= 2; i++) {
            for (j = 0; j <= 2; j++) {
                ver = next / 6;
                hor = next % 6;
                tempfield[ver][hor] = tempboard[i][j];
                next++;
            }
            next += 3;
        }
        return tempfield;
    }

    /**
     * This method copys on cell from a array into an other,
     *
     * @param field
     * @param tofillup
     */
    public static void fill(int[][] field, int[][] tofillup) {
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 6; j++) {
                tofillup[i][j] = field[i][j];
            }
        }
    }

    /**
     * Execution of all search methodes to evaluate a situation
     * 
     * @param field targetfield
     * @param black playerfalg
     */
    public static void fullJudge(int[][] field, boolean black) {
        searchTwoOverThreeInARow(field, black);
        searchTwoInAColumn(field, black);
        searchPossibleFourInARow(field, black);
        searchPossibleFourInAColumn(field, black);
        searchTwoOverThreeInAColumn(field, black);
        searchTwoInADiagonal_TopLeft(field, black);
        searchTwoInADiagonal_BelowLeft(field, black);
        searchTwoOverThreeInADiagonal(field, black);
        searchPossibleFiveInARow(field, black);
        searchPossibleFiveInAColumn(field, black);
        searchPossibleFiveInADiagonal_TopLeft(field, black);
        searchPossibleFiveInADiagonal_TopLeft_UnderUpperMain(field, black);
        searchPossibleFiveInADiagonal_BelowLeft(field, black);
        searchPossibleFiveInADiagonal_BelowLeft_UnderUpperMain(field, black);
    }

    /**
     * Try & error policy to show which rotation will improve the situation of black.
     * @param field targetfield
     * @param black palyerglag
     * @return int[]{quadrant, clock}
     */
    public static int[] searchBestRotation(int[][] field, boolean black) {
        int[][] workfield1 = new int[6][6];
        int quadrant = 0;
        int clock = 0, maxtmp = 0, x = 0;


        int[] maxValue = new int[]{0, 0, 0, 0, 0, 0, 0, 0};


        fill(field, workfield1);
        quadrant = 1;
        clock = -1;
        workfield1 = rotate(field, quadrant, clock);
        if (checkWin(workfield1, black) == true) {
            maxValue[0] = 9999;
        }
        fullJudge(workfield1, black);
        maxValue[0] += getfullValue(workfield1, black);

        fill(field, workfield1);
        quadrant = 1;
        clock = 1;
        workfield1 = rotate(field, quadrant, clock);
        if (checkWin(workfield1, black) == true) {
            maxValue[1] = 9999;
        }
        fullJudge(workfield1, black);
        maxValue[1] += getfullValue(workfield1, black);

        fill(field, workfield1);
        quadrant = 2;
        clock = -1;
        workfield1 = rotate(field, quadrant, clock);
        if (checkWin(workfield1, black) == true) {
            maxValue[2] = 9999;
        }

        fullJudge(workfield1, black);
        maxValue[2] += getfullValue(workfield1, black);

        fill(field, workfield1);
        quadrant = 2;
        clock = 1;
        workfield1 = rotate(field, quadrant, clock);
        if (checkWin(workfield1, black) == true) {
            maxValue[2] = 9999;
        }
        fullJudge(workfield1, black);
        maxValue[3] += getfullValue(workfield1, black);

        fill(field, workfield1);
        quadrant = 3;
        clock = -1;
        workfield1 = rotate(field, quadrant, clock);
        if (checkWin(workfield1, black) == true) {
            maxValue[2] = 9999;
        }
        fullJudge(workfield1, black);
        maxValue[4] += getfullValue(workfield1, black);

        fill(field, workfield1);
        quadrant = 3;
        clock = 1;
        workfield1 = rotate(field, quadrant, clock);
        if (checkWin(workfield1, black) == true) {
            maxValue[2] = 9999;
        }
        fullJudge(workfield1, black);
        maxValue[5] += getfullValue(workfield1, black);

        fill(field, workfield1);
        quadrant = 4;
        clock = -1;
        workfield1 = rotate(field, quadrant, clock);
        if (checkWin(workfield1, black) == true) {
            maxValue[2] = 9999;
        }
        fullJudge(workfield1, black);
        maxValue[6] += getfullValue(workfield1, black);

        fill(field, workfield1);
        quadrant = 4;
        clock = 1;
        workfield1 = rotate(field, quadrant, clock);
        if (checkWin(field, black) == true) {
            maxValue[2] = 9999;
        }
        fullJudge(workfield1, black);
        maxValue[7] += getfullValue(workfield1, black);

        for (int i = 0; i < 8; i++) {
            if (maxtmp <= maxValue[i]) {
                maxtmp = maxValue[i];

            }
        }

        for (int i = 0; i < 8; i++) {
            if (maxtmp == maxValue[i]) {
                x = i + 1;
                break;

            }

        }
        switch (x) {
            case 1: {
                quadrant = 1;
                clock = -1;
            }
            break;
            case 2: {
                quadrant = 1;
                clock = 1;
            }
            break;
            case 3: {
                quadrant = 2;
                clock = -1;
            }
            break;
            case 4: {
                quadrant = 2;
                clock = 1;
            }
            break;
            case 5: {
                quadrant = 3;
                clock = -1;
            }
            break;
            case 6: {
                quadrant = 3;
                clock = 1;
            }
            break;
            case 7: {
                quadrant = 4;
                clock = -1;
            }
            break;
            case 8: {
                quadrant = 4;
                clock = 1;
            }
            break;
        }


        return new int[]{quadrant, clock};
    }

    /**
     * Shows if the player flag who got a winning situation in a Column
     * @param board
     * @param who
     * @return boolean if win = true else false
     */
    public static boolean checkWinColumn(int[][] board, boolean who) {

        for (int i = 0; i < 6; i++) {
            /*initialize sum with 0*/
            int sum = 0;
            for (int j = 0; j < 6; j++) {
                if (who) {
                    if (board[j][i] == 1) {
                        sum += board[j][i];
                    } else {
                        sum = 0;
                    }
                    if (sum == 5) {
                        return true;
                    }
                } else if (!who) {

                    if (board[j][i] == -1) {
                        sum += board[j][i];
                    } else {
                        sum = 0;
                    }

                    if (sum == -5) {
                        return true;
                    }
                }
            }
        }
        return false;

    }

    /**
     * This function calculates the sum of the rows
     * @param who This parameter shows who is playing. If who = true, Black plays, else Red plays
     * @param board is the targetarray
     * @return true if there is a wining situation on board
     */
    public static boolean checkWinRow(int[][] board, boolean who) {

        for (int i = 0; i < 6; i++) {
            /*initialize sum with 0*/
            int sum = 0;
            for (int j = 0; j < 6; j++) {
                if (who) {
                    if (board[i][j] == 1) {
                        sum += board[i][j];
                    } else {
                        sum = 0;
                    }
                    if (sum == 5) {
                        return true;
                    }
                } else if (!who) {
                    if (board[i][j] == -1) {
                        sum += board[i][j];
                    } else {
                        sum = 0;
                    }

                    if (sum == -5) {
                        return true;
                    }
                }

            }
        }
        return false;

    }

    /**
     * This function calculates the sum of the 3 second diagonals
     * @param who This parameter shows who is playing. If who = true, Black plays, else Red plays
     * @param board is the targetarray
     * @return true if there is a wining situation on board
     */
    public static boolean checkWinSecondDiag(int[][] board, boolean who) {
        int sum = 0;
        /*Diagonal from 0|5 to 5|0*/
        for (int i = 0; i < 6; i++) {
            int j = 5 - i;

            if (!who) {
                if (board[j][i] == 1) {
                    sum += board[j][i];
                } else {
                    sum = 0;
                }
                if (sum == 5) {
                    return true;
                }
            } else if (who) {

                if (board[j][i] == -1) {
                    sum += board[j][i];
                } else {
                    sum = 0;
                }

                if (sum == -5) {
                    return true;
                }
            }

        }

        /*Diagonal from 0|4 to 4|0*/
        sum = 0;
        for (int i = 0; i < 5; i++) {
            int j = 4 - i;

            if (!who) {
                if (board[j][i] == 1) {
                    sum += board[j][i];
                } else {
                    sum = 0;
                }
                if (sum == 5) {
                    return true;
                }
            } else if (who) {

                if (board[j][i] == -1) {
                    sum += board[j][i];
                } else {
                    sum = 0;
                }

                if (sum == -5) {
                    return true;
                }
            }
        }

        /*Diagonal from 1|5 to 5|1*/
        sum = 0;
        for (int i = 1; i < 6; i++) {
            int j = 6 - i;

            if (!who) {
                if (board[i][j] == 1) {
                    sum += board[i][j];
                } else {
                    sum = 0;
                }
                if (sum == 5) {
                    return true;
                }
            } else if (who) {

                if (board[i][j] == -1) {
                    sum += board[i][j];
                } else {
                    sum = 0;
                }

                if (sum == -5) {
                    return true;
                }
            }
        }
        return false;

    }

    /**
     * This function calculates the sum of the 3 diagonals
     * @param who This parameter shows who is playing. If who = true, Black plays, else Red plays
     * @param board is the targetarray
     * @return true if there is a wining situation on board
     */
    public static boolean checkWinMainDiag(int[][] board, boolean who) {

        /*Diagonal from 0|0 to 5|5*/

        /*initialize sum with 0*/
        int sum = 0;
        for (int i = 0; i < 6; i++) {

            if (!who) {
                if (board[i][i] == 1) {
                    sum += board[i][i];
                } else {
                    sum = 0;
                }
                if (sum == 5) {
                    return true;
                }
            } else if (who) {

                if (board[i][i] == -1) {
                    sum += board[i][i];
                } else {
                    sum = 0;
                }

                if (sum == -5) {
                    return true;
                }
            }
        }

        /*Diagonal from 0|1 to 4|5*/

        /*initialize sum with 0*/
        sum = 0;
        for (int i = 0; i < 5; i++) {

            if (!who) {
                if (board[i + 1][i] == 1) {
                    sum += board[i + 1][i];
                } else {
                    sum = 0;
                }
                if (sum == 5) {
                    return true;
                }
            } else if (who) {

                if (board[i + 1][i] == -1) {
                    sum += board[i + 1][i];
                } else {
                    sum = 0;
                }

                if (sum == -5) {
                    return true;
                }
            }
        }

        /*Diagonal from 1|0 to 5|4*/

        /*initialize sum with 0*/
        sum = 0;
        for (int i = 0; i < 5; i++) {

            if (!who) {
                if (board[i][i + 1] == 1) {
                    sum += board[i][i + 1];
                } else {
                    sum = 0;
                }
                if (sum == 5) {
                    return true;
                }
            } else if (who) {

                if (board[i][i + 1] == -1) {
                    sum += board[i][i + 1];
                } else {
                    sum = 0;
                }

                if (sum == -5) {
                    return true;
                }
            }
        }
        return false;

    }

    /**
     * A modified version of the checkWin method from the GameEngine.Board
     *
     * @param board is the board that is supposed to be checked
     * @param who palyerflag
     * @return true if ther are 5 equal merbels in a row,column or diagnal oterwise false
     */
    public static boolean checkWin(int[][] board, boolean who) {
        if (checkWinRow(board, who) == true) {
            return true;
        }

        if (checkWinColumn(board, who) == true) {
            return true;
        }

        if (checkWinMainDiag(board, who) == true) {
            return true;
        }

        if (checkWinSecondDiag(board, who) == true) {
            return true;
        }

        return false;
    }
}
